#include <stdio.h>
#include <assert.h>

unsigned srl(unsigned x, int k){
    unsigned xsra = (int) x >> k;

    unsigned mask = ~(-1 << (sizeof(int) * 8 - k));

    xsra &= mask;

    return xsra;

}

int sra(int x, int k){
    int xsrl = (unsigned) x >> k;
    int mask = 1 << (sizeof(int) * 8 - k - 1);
    mask &= xsrl;
    mask = (0 - (mask != 0)) << (sizeof(int) * 8 - k);

    return xsrl | mask;

}


int main(){

    assert(srl(0x12345678, 4) == ((unsigned)0x12345678 >> 4));
    assert(srl(0xFF234567, 4) == ((unsigned)0xFF234567 >> 4));
    assert(sra(0x12345678, 4) == (int)0x12345678 >> 4);
    assert(sra(0xFF234567, 4) == (int)0xFF234567 >> 4);

    return 0;
}
